<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('终端库列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 120px">品牌名称：</label>
                                <select name="manuName" style="width: 220px;">
                                    <option value="">选择品牌</option>
                                    <option th:each="m:${manufacturer}" th:text="${m.MANU_NAME}" th:value="${m.MANU_NAME}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 120px">POS编号：</label>
                                <input type="text" name="posno"/>
                            </li>
                            <li>
                                <label style="width: 120px">SN编号：</label>
                                <input type="text" name="machineNum"/>
                            </li>
                            <li>
                                <label style="width: 120px">状态：</label>
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="0">未使用</option>
                                    <option value="1">已使用</option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 120px">网络类型：</label>
                                <select name="posNetwork">
                                    <option value="">所有</option>
                                    <option value="4">4G</option>
                                    <option value="2">2G</option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 120px">机器版本：</label>
                                <select name="pos_version">
                                    <option value="">所有</option>
                                    <option value="1">1.0</option>
                                    <option value="2">2.0</option>
                                </select>
                            </li>

                            <li>
                                <label style="width: 120px">终端类型：</label>
                                <select name="type" th:with="type=${@dict.getType('terminal_type')}">
                                    <option value="">请选择</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 145px">POS编号起止号段：</label>
                                <input type="text" name="params[start_posno]" >-<input type="text" name="params[end_posno]"   >
                            </li>
                            <li>
                                <label style="width: 190px">SN编号起止号段：</label>
                                <input type="text" name="params[start_sn]"   >-<input type="text" name="params[end_sn]"  >
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="addPos()" shiro:hasPermission="terminal:library:addPos">
                    <i class="fa fa-plus"></i> 终端入库
                </a>
                <a class="btn btn-warning" onclick="exportExcel()" shiro:hasPermission="terminal:library:export">
                    <i class="fa fa-download"></i> 导出SN
                </a>
                <a class="btn btn-success" onclick="exportModel()" shiro:hasPermission="terminal:record:downloada">
                    <i class="fa fa-download"></i> 入库/划拨模板下载
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "terminal/library";
        var terminalTypeDatas = [[${@dict.getType('terminal_type')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "终端库",
                columns: [
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'machineNum',
                    title: 'SN编号'
                },
                {
                    field: 'posno',
                    title: 'POS编号'
                },
                {
                    field: 'channelPosno',
                    title: '渠道posno'
                },
                {
                    field: 'manuNum',
                    title: '品牌编号'
                },
                {
                    field: 'manuName',
                    title: '品牌名称'
                },
                {
                    field: 'type',
                    title: '终端类型',
                    formatter: function(value,row,index){
                        return $.table.selectDictLabel(terminalTypeDatas, value);
                    }
                },
                {
                    field: 'pos_version',
                    title: '机器版本',
                    formatter: function (value, row, index) {
                        if (row.pos_version == 1 ){
                            return '<span style="color: red">1.0</span>';
                        } else if(row.pos_version == 2 ){
                            return '<span style="color: blue">2.0</span>';
                        }
                    },
                },

                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        if (row.status == 0 ){
                            return '<span style="color: red">未使用</span>';
                        } else if(row.status == 1 ){
                            return '<span style="color: blue">已使用</span>';
                        } else {
                            return '<span style="color: red">未知</span>';
                        }
                    },
                    sortable: true
                },
                {
                    field: 'posNetwork',
                    title: '网络类型',
                    formatter: function (value, row, index) {
                        if (row.posNetwork == 2 ){
                            return '<span style="color: red">2G</span>';
                        } else if(row.posNetwork == 4 ){
                            return '<span style="color: blue">4G</span>';
                        } else {
                            return '<span style="color: red">暂无</span>';
                        }
                    },
                    sortable: true
                },
                {
                    field: 'isSync',
                    title: '渠道同步状态',
                    formatter: function (value, row, index) {
                        if (row.isSync == 0 ){
                            return '<span style="color: red">未同步</span>';
                        } else if(row.isSync == 1 ){
                            return '<span style="color: blue">已同步</span>';
                        }
                    },
                    sortable: true
                },
                {
                    field: 'note',
                    title: '同步备注'
                },
                {
                    field: 'createname',
                    title: '添加人'
                },
                {
                    field: 'createtime',
                    title: '添加时间'
                }]
            };
            $.table.init(options);
        });
        function selectManu() {
            var url = ctx + "terminal/manufacturer/selectManufacturer/";
            $.modal.open("选择厂商" , url, '700');
        }
        // 导出数据
        function exportExcel(formId) {
            table.set();
            $.modal.confirm("确定导SN吗？", function() {
                var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
                var params = $("#" + table.options.id).bootstrapTable('getOptions');
                var dataParam = $("#" + currentId).serializeArray();
                dataParam.push({ "name": "orderByColumn", "value": params.sortName });
                dataParam.push({ "name": "isAsc", "value": params.sortOrder });
                $.modal.loading("正在导出数据，请稍后...");
                $.post(table.options.exportUrl, dataParam, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $.modal.alertSuccess(result.msg);
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                });
            });

        }
        function addPos() {
            var url = prefix + "/addPos/";
            $.modal.open("生成终端" , url, '950','600');
        }

        function exportModel() {
            $.modal.confirm("确定要下载模板吗？", function() {
                 var url = prefix + "/exportModel";
                $.get(url, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    } else {
                        $.modal.alertError(result.msg);
                    }
                });
            });
        }

    </script>
</body>
</html>
